﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace B2B.Models
{
    public class BaoGia
    {
        int maBaoGia;

        public int MaBaoGia
        {
            get { return maBaoGia; }
            set { maBaoGia = value; }
        }
        string tapTin;

        public string TapTin
        {
            get { return tapTin; }
            set { tapTin = value; }
        }
        int maSanPham;

        public int MaSanPham
        {
            get { return maSanPham; }
            set { maSanPham = value; }
        }
        string tenSanPham;

        public string TenSanPham
        {
            get { return tenSanPham; }
            set { tenSanPham = value; }
        }
        int maSanPhamMua;

        public int MaSanPhamMua
        {
            get { return maSanPhamMua; }
            set { maSanPhamMua = value; }
        }
        string tenSanPhamMua;

        public string TenSanPhamMua
        {
            get { return tenSanPhamMua; }
            set { tenSanPhamMua = value; }
        }
        string emailNguoiGui;

        public string EmailNguoiGui
        {
            get { return emailNguoiGui; }
            set { emailNguoiGui = value; }
        }
        string emailNguoiNhan;

        public string EmailNguoiNhan
        {
            get { return emailNguoiNhan; }
            set { emailNguoiNhan = value; }
        }
        string link;

        public string Link
        {
            get { return link; }
            set { link = value; }
        }
        int tinhTrang;

        public int TinhTrang
        {
            get { return tinhTrang; }
            set { tinhTrang = value; }
        }
        DateTime ngayBaoGia;

        public DateTime NgayBaoGia
        {
            get { return ngayBaoGia; }
            set { ngayBaoGia = value; }
        }

        public ArrayList DanhSachBaoGia(int page)
        {
            ArrayList list_BaoGia = new ArrayList();
            SqlConnection conn = KetNoi.Connection();
            SqlCommand cmd = new SqlCommand("SP_DANHSACHBAOGIA", conn);
            cmd.Parameters.AddWithValue("@PAGECURENT", page);
            cmd.CommandType = CommandType.StoredProcedure;
            conn.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                BaoGia bg = new BaoGia();
                bg.MaBaoGia = reader.GetInt32(0);
                bg.TapTin = reader.GetString(1);
                bg.MaSanPham = reader.GetInt32(2);
                bg.TenSanPham = reader.GetString(3);
                bg.MaSanPhamMua = reader.GetInt32(4);
                bg.TenSanPhamMua = reader.GetString(5);
                bg.EmailNguoiGui = reader.GetString(6);
                bg.EmailNguoiNhan = reader.GetString(7);
                bg.Link=reader.GetString(8);
                bg.TinhTrang = reader.GetInt32(9);
                bg.NgayBaoGia = reader.GetDateTime(10);
                list_BaoGia.Add(bg);
            }
            conn.Close();
            return list_BaoGia;
        }

        public int TongBaoGia()
        {
            SqlConnection conn = KetNoi.Connection();
            SqlCommand cmd = new SqlCommand("SP_TONGBAOGIA", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            conn.Open();
            int totalRow = int.Parse(cmd.ExecuteScalar().ToString());
            conn.Close();
            return totalRow;
        }

    }
}